package edu.cuit.zhuyimeng.flight.job;

import com.baomidou.dynamic.datasource.annotation.Master;
import edu.cuit.zhuyimeng.flight.dal.mapper.FlightMapper;
import edu.cuit.zhuyimeng.flight.service.IFlightManagerService;
import edu.cuit.zhuyimeng.ticket.api.controller.TicketDispatchApiController;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import tech.powerjob.worker.core.processor.ProcessResult;
import tech.powerjob.worker.core.processor.TaskContext;
import tech.powerjob.worker.core.processor.sdk.BasicProcessor;

/**
 * 销毁航班调度任务
 */
@Component("destroyFlightProcessor")
@RequiredArgsConstructor
@Slf4j
public class DestroyFlightProcessor implements BasicProcessor {

    private final IFlightManagerService flightManagerService;
    private final TicketDispatchApiController ticketDispatchApiController;

    @Override
    @Master
    public ProcessResult process(TaskContext context) throws Exception {
        Long flightId = Long.valueOf(context.getJobParams());
        flightManagerService.removeFlight(flightId);
        ticketDispatchApiController.deleteTicket(flightId);
        log.info("ID为 {} 的航班已被自动销毁（航班流程结束）",flightId);
        return new ProcessResult(true,"成功");
    }
}
